﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Game
{
    namespace RenderTechnique
    {
        class PostProcessRenderTechnique : ShadowRenderTechnique
        {
            public PostProcessRenderTechnique(TechniqueDescription desc)
                : base(desc)
            {
            }

            public void InitPostrocess()
            {
                // down program
                IDK.ShaderProgram programDown = Description.Core.GetShaderProgram("Postprocess\\HDR\\Down");
                programDown.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.Texture0, "inputMap");

                // high program
                IDK.ShaderProgram programHigh = Description.Core.GetShaderProgram("Postprocess\\HDR\\High");
                programHigh.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.Texture0, "inputMap");

                // blur program
                IDK.ShaderProgram programBlur = Description.Core.GetShaderProgram("Postprocess\\HDR\\GaussBlur");
                programBlur.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.Texture0, "inputMap");
                IDK.OutputScreenShadingPass.BlurOffsetParameter blurOffsetParameter = new IDK.OutputScreenShadingPass.BlurOffsetParameter();
                programBlur.AddParameterData(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.Constant2f, "blurOffset", blurOffsetParameter);

                // final program
                IDK.ShaderProgram programFinal = Description.Core.GetShaderProgram("Postprocess\\HDR\\Final");
                programFinal.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.Texture0, "srcImage");
                programFinal.AddParameter(IDK.ShaderProgram.Parameter.Type.ConstantParameter, IDK.ShaderProgram.Parameter.Declaration.Texture1, "hdrImage");

                IDK.RenderTarget rttTemp1 = Description.Core.GetRenderTarget("rttTemp1");
                rttTemp1.AttachTexture(Description.Core.CreateRenderTexture(Description.Renderer.GetViewport().Width / 4, Description.Renderer.GetViewport().Height / 4, IDK.Texture.Format.RGBA, IDK.Texture.PixelType.ByteRGBA8));

                IDK.RenderTarget rttTemp2 = Description.Core.GetRenderTarget("rttTemp2");
                rttTemp2.AttachTexture(Description.Core.CreateRenderTexture(Description.Renderer.GetViewport().Width / 4, Description.Renderer.GetViewport().Height / 4, IDK.Texture.Format.RGBA, IDK.Texture.PixelType.ByteRGBA8));

                Description.Renderer.AddPass(new IDK.OutputScreenShadingPass(RTTOutput, rttTemp1, rttTemp2, programDown, programHigh, programBlur, programFinal, blurOffsetParameter));
            }
        }
    }
}
